package com.thingple.web.bridge.view;

import android.app.Activity;
import android.content.Context;
import android.webkit.JavascriptInterface;
import android.webkit.WebView;

import com.thingple.h5.bridge.AbstractJsBridge;
import com.thingple.h5.bridge.BridgeConfig;

@BridgeConfig(moduleName = "view")
public class ViewJsBridgeImpl extends AbstractJsBridge implements ViewJsBridge {

    public ViewJsBridgeImpl(WebView webView, Context context) {
        super(webView, context);
    }

    @Override
    public void destroy() {

    }

    @JavascriptInterface
    @Override
    public void open(String url) {

        getWebView().loadUrl(url);// TODO 弹出一个新界面
    }

    @JavascriptInterface
    @Override
    public void go(String url) {
        getWebView().loadUrl(url);
    }

    @JavascriptInterface
    @Override
    public void close() {
        Context context = getContext();
        if (context != null && context instanceof Activity) {// 关闭 activity
            Activity activity = (Activity) context;
            activity.finish();
        }
    }
}
